from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings

def generate_verify_email_url(user):
    """
    生成邮箱验证链接
    :param user: 当前登录用户
    :return: verify_url
    """
    serializer = Serializer(settings.SECRET_KEY, expires_in=3600*24)
    data = {'user_id': user.id}
    token = serializer.dumps(data).decode()
    return token

def check_verify_token(token):
    #创建实例
    serializer = Serializer(settings.SECRET_KEY, expires_in=3600*24)
    try:
        data = serializer.loads(token)
    except:
        return None
    return data.get('user_id')
